// pages/classify/shopDetail/shopDetail.js
import request from "../../../utils/request"
Page({
  
  /**
   * 页面的初始数据
   */
  data: {
    hour: '',
    minutes: '',
    seconds: '',
    shopItem: {},
    nowIndex: "basic",
    number: 1,
    shopcarList:[],

    // 轮播图信息
    bannerData:{
      background:[],
      indicatorDots: true,
      vertical: false,
      autoplay: true,
      circular: true,
      interval: 2000,
      duration: 1000,
      previousMargin: 0,
      nextMargin: 0,
      
    },
  },
  back() {
    wx.switchTab({
      url: '../classify',
    })
  },
  remove() {
    if (this.data.number > 1) {
      this.data.number--;
      this.setData({ number: this.data.number })
    }
  },
  add() {
    this.data.number++;
    this.setData({ number: this.data.number })
  },
  tap(e) {
    let { option } = e.target.dataset;
    this.setData({ nowIndex: option })
  },
  addShop(e) {
    let { item } = e.target.dataset;
    item.num=this.data.number;
    this.setData({shopItem:item})
    request('/addshopcar', item, { 'content-type': 'application/json' }, 'GET')
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const tempObj = decodeURIComponent(options.obj)
    const obj = JSON.parse(tempObj);
    // this.setData({img:obj.img,title:obj.title,price:obj.price });
    // 修改轮播
    let arr = [obj.img]
    arr.push(obj.img)
    this.setData({
      ["bannerData.background"]:arr
    })
    console.log(this.data);
    this.setData({ shopItem: obj });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    let timer = setInterval(() => {
      var date = new Date().getTime();
      var date2 = new Date("2021-12-1").getTime();
      var cha = date2 - date;
      var days = parseInt(cha / 1000 / 3600 / 24);
      var hours = parseInt((cha - days * 24 * 3600 * 1000) / 1000 / 3600) < 10 ? '0' + parseInt((cha - days * 24 * 3600 * 1000) / 1000 / 3600) : parseInt((cha - days * 24 * 3600 * 1000) / 1000 / 3600);
      var minutes = parseInt((cha - days * 24 * 3600 * 1000 - hours * 3600 * 1000) / 1000 / 60) < 10 ? '0' + parseInt((cha - days * 24 * 3600 * 1000 - hours * 3600 * 1000) / 1000 / 60) : parseInt((cha - days * 24 * 3600 * 1000 - hours * 3600 * 1000) / 1000 / 60);
      var seconds = parseInt((cha - days * 24 * 3600 * 1000 - hours * 3600 * 1000 - minutes * 60 * 1000) / 1000) < 10 ? '0' + parseInt((cha - days * 24 * 3600 * 1000 - hours * 3600 * 1000 - minutes * 60 * 1000) / 1000) : parseInt((cha - days * 24 * 3600 * 1000 - hours * 3600 * 1000 - minutes * 60 * 1000) / 1000);
      this.setData({ hour: hours, minutes: minutes, seconds: seconds })
    }, 1000);
    request('/getshopcarList', {}, { 'content-type': 'application/json' }, 'GET').then(res=>{
      this.setData({shopcarList:res})
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})